﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMS
{
    public partial class CategoryForm : Form
    {
        public CategoryForm()
        {
            InitializeComponent();
        }
        
        private void CategoryForm_Load(object sender, EventArgs e)
        {
            PMS.BLL.Category category = new PMS.BLL.Category();
            PMS.Model.Category topCategory = new PMS.Model.Category();
            topCategory.Id = 0;
            topCategory.Name = "顶级类";
            topCategory.Path = "0_0";
            topCategory.Pid = "0";
            IList<PMS.Model.Category> cList = category.GetAllList();
            cList.Insert(0,topCategory);
            this.cmb_Pid.DataSource = cList;
            cmb_Pid.DisplayMember = "Name";
            cmb_Pid.ValueMember = "Id";
            cmb_Pid.SelectedItem = "顶级类";
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PMS.Model.Category c = new PMS.Model.Category();
            c.Id = 0;
            c.Name = txt_name.Text;
            c.Pid = cmb_Pid.SelectedValue.ToString();
            c.Path = "";
            PMS.BLL.Category bllc = new PMS.BLL.Category();
            if (bllc.Insert(c))
            {
                MessageBox.Show("添加成功");
            }
            else
            {
                MessageBox.Show("添加失败");
            }
            
        }
    }
}
